home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <X11/Intrinsic.h>
- #include <Xm/Xm.h>
- #include <GL/GLwMDrawA.h>
- #include <GL/gl.h>
- #include <GL/glx.h>
- #include "interfere.h"
-
- int sten_size = 0;
-
- static XVisualInfo * visual_info = NULL;
- static GLXContext rendering_context;
- static Widget canvas = NULL;
-
- static int dblBuf[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
- GLX_STENCIL_SIZE, 4,
- GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4,
- None};
- static int sngBuf[] = {GLX_RGBA,
- GLX_STENCIL_SIZE, 4,
- GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4,
- None};
-
- XVisualInfo *
- getVisualInfo (Display * display)
- {
- XVisualInfo * vi = glXChooseVisual(display, DefaultScreen(display), dblBuf);
- if (vi == NULL) {
- vi = glXChooseVisual(display, DefaultScreen(display), sngBuf);
- if (vi != NULL) {
- fprintf(stderr,
- "Could not find a double buffered visual\n");
- fprintf(stderr, " -- reverting to single buffer\n");
- }
- else {
- fprintf(stderr, "Could not find a suitable visual -- aborting\n");
- exit(1);
- }
- }
- glXGetConfig(display, vi, GLX_STENCIL_SIZE, &sten_size);
- visual_info = vi;
- return vi;
- }
-
- static void
- exposeCallback (Widget w, XtPointer client, XtPointer callback)
- {
- drawScene();
- }
-
- Widget
- initRenderingArea (Widget parent)
- {
- Arg args[0x2];
- int width = 0, height = 0;
-
- XtVaGetValues(parent, XmNwidth, &width, XmNheight, &height, NULL);
- canvas = XtVaCreateManagedWidget("canvas", glwMDrawingAreaWidgetClass,
- parent,
- XmNwidth, width,
- XmNheight, height,
- GLwNattribList, dblBuf,
- NULL);
- XtAddCallback(canvas, XmNexposeCallback, exposeCallback, NULL);
-
- XtVaGetValues(canvas, GLwNvisualInfo, &visual_info, NULL);
- rendering_context = glXCreateContext(XtDisplay(parent), visual_info,
- NULL, GL_TRUE);
- XtManageChild(parent);
-
-
- return canvas;
- }
-
- void
- setCurrentRenderingContext (Display * display)
- {
- glXMakeCurrent(display, XtWindow(canvas), rendering_context);
- initGraphics ();
- }
-
- void
- showCurrent (void)
- {
- glXSwapBuffers(XtDisplay(canvas), XtWindow(canvas));
- }
-
-